package com.bjb.vr.operation.controller;

import com.bjb.vr.common.ao.OptClassifyAo;
import com.bjb.vr.common.ao.OptFeatureAo;
import com.bjb.vr.common.ao.OptTopicAo;
import com.bjb.vr.common.ao.ResDictionaryAo;
import com.bjb.vr.common.result.BaseErrorCode;
import com.bjb.vr.common.result.BaseResult;
import com.bjb.vr.common.result.CommonResult;
import com.bjb.vr.common.service.*;
import com.bjb.vr.common.vo.OptClassifyVo;
import com.bjb.vr.common.vo.OptFeatureVo;
import com.bjb.vr.common.vo.OptTopicVo;
import com.bjb.vr.common.vo.ResDictionaryVo;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 云端资源配置
 * @author: hujingbo
 * @create: 2022-12-13 13:42
 **/
@RestController
@RequestMapping("/api/operation/v1")
public class OptCloudResourceConfigController {

    @Resource
    private OptFeatureConfigService featureConfigService;

    @Resource
    private OptClassifyConfigService classifyConfigService;

    @Resource
    private OptTopicConfigService topicConfigService;

    @Resource
    private ResCascadeService resCascadeService;

    @Resource
    private ResDictionaryService dictionaryService;


    //----------------------------------------------推荐位----------------------------------------------

    /**
     * 查询推荐位配置--集合
     *
     * @param optFeatureAo
     * @return
     */
    @PostMapping("/queryFeatureList")
    public BaseResult queryFeatureList(@RequestBody OptFeatureAo optFeatureAo) {
        List<OptFeatureVo> featureVoList = featureConfigService.queryFeatureList(optFeatureAo);
        return CommonResult.Ok().setResult(featureVoList);
    }

    /**
     * 查询推荐位配置--单条
     *
     * @param optFeatureAo
     * @return
     */
    @PostMapping("/queryFeatureOne")
    public BaseResult queryFeatureOne(@RequestBody OptFeatureAo optFeatureAo) {
        OptFeatureVo featureVo = featureConfigService.queryFeatureOne(optFeatureAo);
        return CommonResult.Ok().setResult(featureVo);
    }

    /**
     * 新增推荐位配置
     *
     * @param optFeatureAo
     * @return
     */
    @PostMapping("/addFeature")
    public BaseResult addFeature(@RequestBody OptFeatureAo optFeatureAo) {
        Assert.notNull(optFeatureAo.getResId(), "资源ID不能为空");
        Assert.notNull(optFeatureAo.getResImage(), "资源图片不能为空");
        return featureConfigService.addFeature(optFeatureAo);
    }

    /**
     * 编辑推荐位配置
     *
     * @param optFeatureAo
     * @return
     */
    @PostMapping("/editFeature")
    public BaseResult editFeature(@RequestBody OptFeatureAo optFeatureAo) {
        return featureConfigService.editFeature(optFeatureAo);
    }

    /**
     * 删除推荐位配置
     *
     * @param optFeatureAo
     * @return
     */
    @PostMapping("/deleteFeature")
    public BaseResult deleteFeature(@RequestBody OptFeatureAo optFeatureAo) {
        return featureConfigService.deleteFeature(optFeatureAo);
    }

    //----------------------------------------------分 类----------------------------------------------

    /**
     * 查询版本类型
     *
     * @param optClassifyAo
     * @return
     */
    @PostMapping("/queryVersion")
    public BaseResult queryVersion(@RequestBody OptClassifyAo optClassifyAo) {
        List<ResDictionaryVo> dictionaryVos = null;
        if (optClassifyAo.getDicType().equals("1008")) {
            dictionaryVos = resCascadeService.getResDictionaryDJList("0");
        } else if (optClassifyAo.getDicType().equals("1009")) {
            dictionaryVos = resCascadeService.getResDictionaryDJList("1");
        } else {
            ResDictionaryAo dictionaryAo = new ResDictionaryAo();
            dictionaryAo.setDictType(optClassifyAo.getDicType());
            dictionaryVos = dictionaryService.queryDictionaryByPeriodLink(dictionaryAo);
        }
        return CommonResult.Ok().setResult(dictionaryVos);
    }

    /**
     * 查询分类配置--集合
     *
     * @param optClassifyAo
     * @return
     */
    @PostMapping("/queryClassifyList")
    public BaseResult queryClassifyList(@RequestBody OptClassifyAo optClassifyAo) {
        List<OptClassifyVo> classifyVoList = classifyConfigService.queryClassifyList(optClassifyAo);
        return CommonResult.Ok().setResult(classifyVoList);
    }

    /**
     * 查询分类配置--单条
     *
     * @param optClassifyAo
     * @return
     */
    @PostMapping("/queryClassifyOne")
    public BaseResult queryClassifyOne(@RequestBody OptClassifyAo optClassifyAo) {
        OptClassifyVo classifyVo = classifyConfigService.queryClassifyOne(optClassifyAo);
        return CommonResult.Ok().setResult(classifyVo);
    }

    /**
     * 新增分类配置
     *
     * @param optClassifyAo
     * @return
     */
    @PostMapping("/addClassify")
    public BaseResult addClassify(@RequestBody OptClassifyAo optClassifyAo) {
        return classifyConfigService.addClassify(optClassifyAo);
    }

    /**
     * 编辑分类配置
     *
     * @param optClassifyAo
     * @return
     */
    @PostMapping("/editClassify")
    public BaseResult editClassify(@RequestBody OptClassifyAo optClassifyAo) {
        return classifyConfigService.editClassify(optClassifyAo);
    }

    /**
     * 删除分类配置
     *
     * @param optClassifyAo
     * @return
     */
    @PostMapping("/deleteClassify")
    public BaseResult deleteClassify(@RequestBody OptClassifyAo optClassifyAo) {
        return classifyConfigService.deleteClassify(optClassifyAo);
    }

    //----------------------------------------------专 题----------------------------------------------

    /**
     * 查询专题配置--集合
     *
     * @param optTopicAo
     * @return
     */
    @PostMapping("/queryTopicList")
    public BaseResult queryTopicList(@RequestBody OptTopicAo optTopicAo) {
        List<OptTopicVo> topicVoList = topicConfigService.queryTopicList(optTopicAo);
        return CommonResult.Ok().setResult(topicVoList);
    }

    /**
     * 查询专题配置--单条
     *
     * @param optTopicAo
     * @return
     */
    @PostMapping("/queryTopicOne")
    public BaseResult queryTopicOne(@RequestBody OptTopicAo optTopicAo) {
        OptTopicVo topicVo = topicConfigService.queryTopicOne(optTopicAo);
        return CommonResult.Ok().setResult(topicVo);
    }

    /**
     * 新增分类配置
     *
     * @param optTopicAo
     * @return
     */
    @PostMapping("/addTopic")
    public BaseResult addTopic(@RequestBody OptTopicAo optTopicAo) {
        return topicConfigService.addTopic(optTopicAo);
    }

    /**
     * 编辑分类配置
     *
     * @param optTopicAo
     * @return
     */
    @PostMapping("/editTopic")
    public BaseResult editTopic(@RequestBody OptTopicAo optTopicAo) {
        return topicConfigService.editTopic(optTopicAo);
    }

    /**
     * 删除分类配置
     *
     * @param optTopicAo
     * @return
     */
    @PostMapping("/deleteTopic")
    public BaseResult deleteTopic(@RequestBody OptTopicAo optTopicAo) {
        return topicConfigService.deleteTopic(optTopicAo);
    }
}
